﻿using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Text;
using Autofac;
using Autofac.Extensions;
using Autofac.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.AspNetCore.Mvc.Controllers;

namespace Shared.AutofacHelper
{
    public static class AutofacExtensions
    {
        /// <summary>
        /// 使用Autofac 接管IoC Aop
        /// </summary>
        /// <param name="builder"></param>
        /// <returns></returns>
        public static IHostBuilder UseAutofacTransientDependencyInjection(this IHostBuilder builder, Action<ContainerBuilder> configurationAction = null)
        {
            return builder.UseServiceProviderFactory(new AutofacServiceProviderFactory(configurationAction));
        }
        ///// <summary>
        ///// 使用Autofac
        ///// </summary>
        ///// <param name="service"></param>
        ///// <returns></returns>
        //public static IServiceCollection AddAutofac(this IServiceCollection service)
        //{
        //    return service.Replace(ServiceDescriptor.Transient<IControllerActivator, ServiceBasedControllerActivator>());
        //}

        //public static T Resolve<T>(this Shared.Contracts.IDependency dependency)
        //{
        //    return default(T);
        //}
    }
}
